import Vue from 'vue';
import Router from 'vue-router';

// 未登录首页
import Home from '@/components/pages/Home';
import MainContainer from '@/components/containers/MainContainer';

// 滚动条位置
import scrollBehavior from '@/router/scrollBehavior';

import main from '@/router/main';
// 浏览器兼容提示页
Vue.use(Router);

const router = new Router({
  mode: 'history',        /* 路由类型设定 */
  scrollBehavior,
  routes: [
    {
      // 未登录首页
      path: '/',
      name: 'Home',
      component: Home,
      meta: {
        title: '优小招',
      },
    },
    {
      // 应用主体容器
      path: '/main',
      name: 'MainContainer',
      component: MainContainer,
      children: main,
      meta: {
        scrollToTop: true,
      },
    },
  ],
});

// 设置页面标题
router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next();
});

export default router;
